#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <algorithm>
#include <string>
#include <iostream>

struct Person {
    std::string name;
    double height;
} persons[50];

bool MyCompare(const Person& a, const Person& b) {
    if (a.name[0] != b.name[0]) {
        return a.name[0] == 'm';
    }

    if (a.name[0] == 'm') {
        return a.height < b.height;
    }

    return a.height > b.height;
}

/**
 * 
 * 时间复杂度：O(nlogn)
 * 空间复杂度：O(nL)
 * 
 * 合影效果
 * @return
 */
int main() {

    int n;
    scanf("%d", &n);

    for (int i = 0; i < n; i++) {
        std::string name;
        double height;
        std::cin >> name >> height;
        persons[i].name = name;
        persons[i].height = height;
    }

    std::sort(persons, persons + n, MyCompare);

    for (int i=0; i< n; i++) {
        printf("%.2f ", persons[i].height);
    }


    return 0;
}



